package learn.particleSys;

import processing.core.PApplet;
import processing.core.PVector;

public class Particle {
	private PApplet p;

	private PVector location;
	private PVector velocity;
	private PVector acceleration;
	float lifespan;

	public Particle(PApplet parent, PVector initLocation) {
		p = parent;

		location = initLocation.get();
		velocity = new PVector(p.random(-1, 1), p.random(-2, 0));
		acceleration = new PVector(0, 0.05f);
		lifespan = 255.0f;
	}

	public void run() {
		update();
		display();
	}

	public void update() {
		velocity.add(acceleration);
		location.add(velocity);
		lifespan -= 2.0f;
	}

	public void display() {
		p.stroke(0, lifespan);
		p.strokeWeight(2);
		p.fill(127, lifespan);
		p.ellipse(location.x, location.y, 8, 8);
	}

	public boolean isDead() {
		return lifespan < 0.0f;
	}
}
